﻿namespace com.stifel.BranchMgmtDao
{
    using System;
    using System.Collections.Generic;
    using System.Xml.Serialization;

    using com.stifel.Extensions.ObjectExtensions;
    using com.stifel.Extensions.StringExtensions;

    [Serializable]
    [XmlRoot( "Notification" )]
    public class Notification
    {
        #region Properties

        public DateTime? Created
        {
            get;
            set;
        }

        public DateTime? LastNotified
        {
            get;
            set;
        }

        public Guid UniqueId
        {
            get;
            set;
        }

        #endregion Properties
    }

    [Serializable]
    [XmlRoot( "Notifications" )]
    public class Notifications
    {
        #region Fields

        List<Notification> _Items;

        #endregion Fields

        #region Properties

        public List<Notification> Items
        {
            get
            {
                if ( _Items == null )
                    _Items = new List<Notification>( );
                return _Items;
            }
            set
            {
                _Items = value;
            }
        }

        #endregion Properties

        #region Methods

        public static Notifications Deserialize( string value )
        {
            if ( string.IsNullOrEmpty( value ) )
                return new Notifications( );

            string start = "<Notifications>".HtmlEncode( );
            string end = "</Notifications>".HtmlEncode( );

            int a = value.IndexOf( start );
            int b = value.IndexOf( end ) + end.Length;
            int c = value.Length;
            string s = value.Substring( a, c - a - ( c - b ) );

            Notifications o = new Notifications( );
            if ( !string.IsNullOrEmpty( s ) )
                o = s.HtmlDecode( ).DeserializeFromXml<Notifications>( );
            return o;
        }

        public string Serialize( )
        {
            if ( this == null )
                return string.Empty;

            return this.SerializeToXml<Notifications>( ).HtmlEncode( );
        }

        #endregion Methods
    }
}